import { defHttp } from '/@/utils/http/axios';
import { UploadFileParams } from '/#/axios';
import { UploadApiResult } from './model/uploadModel';

enum Api {
  GetTemplateDefinePage = '/workflow/workItemInst/getTemplateDefinePage',
  GetTemplateData = '/workflow/workItemInst/getTemplateData',
  SaveTemplateData = '/workflow/workItemInst/saveTemplateData',
  GetFormOptions = '/model/tablemodel/getFormOptions',
  GetFormModelFields = '/model/tablemodel/getFormModelFields',
  GetTemplateDataFromOuterBpmn = '/workflow/workItemInst/getTemplateDataFromOuterBpmn',
  DeleteTemplate = '/workflow/workItemInst/deleteTempalte',
  ImportTemplate = '/workflow/workItemInst/newImportTemplate',
  // /(code)
}

export const saveTemplateDataApi = (params) =>
  defHttp.post({
    url: Api.SaveTemplateData,
    params,
  });
export const importTemplateApi = (params) =>
  defHttp.post({
    url: Api.ImportTemplate,
    params,
  });

export const getTemplateDataApi = (params) =>
  defHttp.get({
    url: Api.GetTemplateData,
    params,
  });

export const getTemplateDefinePageApi = (params) =>
  defHttp.get({
    url: Api.GetTemplateDefinePage,
    params,
  });
export const getFormOptions = (params) =>
  defHttp.get({
    url: Api.GetFormOptions,
    params,
  });
export const getFormModelFields = (code) =>
  defHttp.get({
    url: Api.GetFormModelFields + '/' + code,
  });

export const getTemplateDataFromOuterBpmn = (params) =>
  defHttp.post({
    url: Api.GetTemplateDataFromOuterBpmn,
    params,
  });
export function uploadDataFromOuterBpmn(
  params: UploadFileParams,
  onUploadProgress: (progressEvent: ProgressEvent) => void,
) {
  return defHttp.uploadFile<UploadApiResult>(
    {
      url: Api.GetTemplateDataFromOuterBpmn,
      onUploadProgress,
    },
    params,
  );
}

export const deleteTemplate = (id) =>
  defHttp.post({
    url: Api.DeleteTemplate + '/' + id,
  });
